PRG 1.0 TXT

/*
	Shader Program for Instancing Sample
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	type		= e_program.DIFFUSE_INST;
	layer_bits	= e_render_layer_bits.ALL;
	
	ubo_data	= array /*UBO*/ {
		{ "inMaterial", e_program_data.MATERIAL }
	}

	textures	= array /*ProgramTexture*/ {
		{ "unDiffuseMap",  e_texture.DIFFUSE },
		{ "unPerMeshData", e_texture.INSTANCE_DATA }
	}
	
	uniforms	= array /*string*/ {
		"transform", "unTransform."
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0
#define ATTR_NORMAL		1
#define ATTR_TEXCOORD	2

layout(location = ATTR_POSITION)	in vec3  inPosition;
layout(location = ATTR_TEXCOORD)	in vec3  inTexcoord;

uniform samplerBuffer	unPerMeshData;

uniform struct TTransform {
	mat4	MVP;
} unTransform;


out	TVertexData {
	vec3	vTexcoord;
	vec4	vColor;
} Output;


const int	i_elemsize = 5;		// == vec4[5]

void main()
{
	int	size = textureSize( unPerMeshData );
	int	i	 = gl_InstanceID * i_elemsize;
	
	mat4	model = mat4( texelFetch( unPerMeshData, i+0 ),
						  texelFetch( unPerMeshData, i+1 ),
						  texelFetch( unPerMeshData, i+2 ),
						  texelFetch( unPerMeshData, i+3 ) );
	vec4	color = texelFetch( unPerMeshData, i+4 );
	
	gl_Position		 = unTransform.MVP * model * vec4(inPosition, 1.0);
	Output.vTexcoord = inTexcoord;
	Output.vColor 	 = color;
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0, index = 0)	out vec4  outColor;

uniform samplerCube		unDiffuseMap;

in	TVertexData {
	vec3	vTexcoord;
	vec4	vColor;
} Input;

layout(std140)
uniform inMaterial {
	vec4	vDiffuseColor;
} unMaterial;

void main()
{
	outColor = texture( unDiffuseMap, Input.vTexcoord ) * unMaterial.vDiffuseColor * Input.vColor;
}

// [END]
